<?php

namespace App\Models;


class Order extends Orm
{


    protected $table = 'order';
    protected $dateFormat = 'U';
    public $timestamps = true;

    protected $casts = [
        'goods_snap' => 'json',
    ];

    public function userInfo()
    {
        return $this->belongsTo(Users::class, 'user_id', 'id');
    }

    public function dragonInfo()
    {
        return $this->belongsTo(Drag::class, 'dragon_id');
    }

    public function getPayAtAttribute()
    {
        return $this->attributes['pay_at'] ? date('Y-m-d H:i:s', $this->attributes['pay_at']) : '';
    }

    public function getPayTotalAttribute()
    {
        return sprintf("%.2f", $this->attributes['pay_total']/100);
    }

    public function getPriceRealAttribute()
    {
        return sprintf("%.2f", $this->attributes['price_real']/100);
    }
}
